package team.tttxs.ct.controller;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;

import team.tttxs.ct.redis.dao.RedisBuddy;
import team.tttxs.ct.service.UserService;

@RestController
@EnableAutoConfiguration
@MapperScan("team.tttxs.ct.mybatis.mapper")
@ComponentScan(value = {"team.tttxs.ct.service.impl", 
						"team.tttxs.ct.hibernate.dao.impl",
						"team.tttxs.ct.redis.dao"
						})
@EntityScan(value = "team.tttxs.ct.domain")
public class SampleController {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }
    
    @Autowired	
    private UserService userService;
    
    @Autowired
    private RedisBuddy redisBuddy;

    @RequestMapping(value = "/get", produces = {"application/json;charset=UTF-8"})
    public Object getUser(){
    	if(redisBuddy.exists("key")){
    		System.out.println(redisBuddy.get("key"));
    	}else{
    		redisBuddy.set("key", 123);
    	}
    	return userService.selectAllUser();
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}
